package cli

import (
	"github.com/micro/go-micro/cmd"
	sms "git.oschina.net/fanbuchi/xgggh/sms/proto/sms"
	"github.com/micro/go-micro/client"
	//"github.com/micro/go-micro/metadata"
	"golang.org/x/net/context"
	"errors"
)

func Validate(req *sms.ValidateReq)(*sms.ValidateRsp,error) {
	cmd.Init()

	// Use the generated client stub
	_client:=client.DefaultClient
	cl := sms.NewSmsService("com.xgggh.srv.sms", _client)

	// Set arbitrary headers in context
	/*ctx := metadata.NewContext(context.Background(), map[string]string{
		"X-User-Id": "john",
		"X-From-Id": "script",
	})*/
	ctx:=context.Background()
	// Make request
	rsp, err := cl.Validate(ctx, req)
	if err != nil {
		return nil,err
	}
	if rsp ==nil|| !rsp.Ok{
		return nil,errors.New("验证码验证错误")
	}
	return rsp,nil
}

